package org.example.auth.controller;
import com.example.common.utils.JWTUTils;

import com.example.common.result.Result;
import com.example.model.emp.pojo.Employee;
import lombok.extern.slf4j.Slf4j;
import org.example.auth.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class AdminLoginController {
    @Autowired
    private EmpService empService;
    @PostMapping("/fastget/admin/login")
    public Result login(@RequestBody Employee employee){
        Employee emp = empService.getByUsernameAndPassword(employee);
        if (emp!=null){
            Map<String, Object> stringStringHashMap = new HashMap<>();
            stringStringHashMap.put("id",emp.getEmployeeId());
            stringStringHashMap.put("name",emp.getName());
            stringStringHashMap.put("username",emp.getUsername());
            String generate = JWTUTils.generate(stringStringHashMap);
            return Result.success(generate);
        }
        return Result.error("用户或者密码错误");
    }
}
